package Game.Buff;

import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import Game.Objects.GOPlayer;

/** Debuff Hunger class
 * Description: decrease Min.Damage and Max.Damage by 50%
 * @author Aikidos
 */
public class DebuffHunger extends BuffBase {

	private int _decMinDamage;
	private int _decMaxDamage;
	
	public DebuffHunger(BuffManager buffManager) throws SlickException {
		super(buffManager);
		
		_isUnlimited = true;
		
		_icon = new Image("res/gfx/buff/hunger.png");
	}
	
	@Override
	public void init() {
		if (getBuffManager().getOwner().isPlayer()) {
			GOPlayer player = (GOPlayer) getBuffManager().getOwner();
			
			_decMinDamage = player.MinDamage / 2;
			_decMaxDamage = player.MaxDamage / 2;
			
			player.MinDamage -= _decMinDamage;
			player.MaxDamage -= _decMaxDamage;
		}
	}

	@Override
	public void update(int delta) throws SlickException {
		if (getBuffManager().getOwner().isPlayer()) {
			GOPlayer player = (GOPlayer) getBuffManager().getOwner();
			if (player.getHunger() < 850) getBuffManager().remove(this);
		}
	}

	@Override
	public void step() {
		if (getBuffManager().getOwner().isPlayer()) {
			GOPlayer player = (GOPlayer) getBuffManager().getOwner();
			
			player.MinDamage += _decMinDamage;
			player.MaxDamage += _decMaxDamage;
			
			_decMinDamage = player.MinDamage / 2;
			_decMaxDamage = player.MaxDamage / 2;
			
			player.MinDamage -= _decMinDamage;
			player.MaxDamage -= _decMaxDamage;
		}
	}
	
}
